#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>

#include "inputcore.h"
#include "qmlhelper.h"

static QObject *inputCoreInstance(QQmlEngine *qmlengine, QJSEngine * engine)
{
    Q_UNUSED(qmlengine);
    InputCore * ins = new InputCore(engine);
    ins->listenClassNameList << "QQuickTextField" << "QQuickTextArea";
    return ins;
}

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;

    qmlRegisterSingletonType<InputCore>(
                "InputMethod", 1, 0,
                "Input", inputCoreInstance);
    QmlHelper qmlHelper;
    engine.rootContext()->setContextProperty("helper", &qmlHelper);

    engine.load(QUrl(QLatin1String("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}
